package osami.communication;

import java.io.IOException;

/**
 * Connection listener factory creates connection listener objects.
 * 
 * @author osami
 *
 */
public class ConnectionListenerFactory
{
	private Activator iEngine = null;
	private CommServer iCommServer = null;
	
	public static final int TCPIP_LISTENER = 0;
	public static final int BLUETOOTH_LISTENER = 1;
	public static final int MC_LISTENER = 2;
	public static final int BT_ADHOC_LISTENER = 3;

	/**
	 * Creates a new instance of ConnectionListenerFactory.
	 * 
	 * @param aEngine
	 * @param aCommServer
	 */
	public ConnectionListenerFactory( Activator aEngine, CommServer aCommServer )
	{
		iEngine = aEngine;
		iCommServer = aCommServer;
	}
	
	/**
	 * Creates and returns a connection listener object.
	 * 
	 * @param aType
	 * @return ConnectionListener
	 * @throws IOException
	 * @throws OsamiException 
	 */
	public ConnectionListener createListener( int aType ) throws IOException, OsamiException
	{
		switch ( aType )
		{
		case TCPIP_LISTENER: return new TCPIPConnectionListener( iEngine, iCommServer );
		case BLUETOOTH_LISTENER: return new BluetoothConnectionListener( iEngine, iCommServer );
		case MC_LISTENER: return new TCPIPMulticastListener( iEngine, iCommServer );
		case BT_ADHOC_LISTENER: return new BluetoothAdHoc ( iEngine, iCommServer );
		default:
		{
			throw new IOException( "ERROR: Invalid connection type: " + aType );
		}
		}
	}
}
